package com.hzw.saas.web.im.im;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

/**
 * 聊天服务启动器
 * @author sonam
 * @sine 2021/10/21 10:20 上午
 */
@Slf4j
@Component
@Scope("singleton")
public class ImServerContainer {
    /**
     * 聊天实实例
     */
    private Thread imThread;

    @Resource
    private SaasImServer saasImServer;

    @PostConstruct
    public void init() {
        imThread = new Thread(saasImServer);
        imThread.start();

        // TODO 一些额外的处理，比如初始化
    }

    @PreDestroy
    public void close() {
        log.info("正在释放Netty Websocket相关连接...");
        saasImServer.close();
        imThread.interrupt();
        log.info("系统关闭！");
    }

}
